
<template>
  <el-dialog
    title="题目预览"
    :visible="showDialog"
    width="50%"
    @close="onClose"
  >
    <el-row type="flex" justify="space-between">
      <el-col>【题型】: {{ questionData.questionType | formatQuestionType }}</el-col>
      <el-col>【编号】: {{ questionData.id }}</el-col>
      <el-col>【难度】: {{ questionData.difficulty | formatDifficulty }}</el-col>
      <el-col>【标签】: {{ questionData.tags }}</el-col>
    </el-row>
    <el-row type="flex" justify="space-between" style="margin-top: 20px">
      <el-col>【学科】: {{ questionData.subjectName }}</el-col>
      <el-col>【目录】: {{ questionData.directoryName }}</el-col>
      <el-col>【方向】: {{ questionData.direction }}</el-col>
      <el-col></el-col>
    </el-row>
    <hr style="margin-top: 20px" />
    <div>【题干】:</div>
    <div style="color: blue" v-html="questionData.question" />
    <!-- 单选 -->
    <div style="padding-left: 30px" v-if="parseInt(questionData.questionType) === 1">
    <p>单选题  选项:(以下的选中项为答案)</p>
      <div v-for="item in questionData.options" :key="item.id" style="margin-top: 10px" >
        <el-radio
          :label="item.title"
          :value="radio"
          style="margin-top: 10px"
        />
      </div>
    </div>
    <!-- 多选 -->
    <div style="padding-left: 30px" v-if="parseInt(questionData.questionType) === 2">
    <p>多选题  选项:(以下的选中项为答案)</p>
      <div v-for="item in questionData.options" :key="item.id" style="margin-top: 10px" >
        <el-checkbox-group v-model="checkBox">
          <el-checkbox
          :label="item.title"
          style="margin-top: 10px"
        />
        </el-checkbox-group>
      </div>
    </div>
    <hr />
    【参考答案】:
    <el-button type="danger" size="small" @click="playVideo"
      >视频答案解析</el-button
    >
    <br /><br />
    <video
      v-if="showVideo"
      :src="questionData.videoURL"
      controls
      style="width: 400px; height: 225px"
    ></video>
    <hr />
    【答案解析】:
    <div
      v-html="questionData.answer || '无'"
      style="display: inline-block"
    ></div>
    <hr />
    【题目备注】:
    <div
      v-html="questionData.remarks || '无'"
      style="display: inline-block"
    ></div>
  </el-dialog>
</template>

<script>
import { detail } from '@/api/hmmm/questions'
import { questionType, difficulty } from '@/api/hmmm/constants'
export default {
  filters: {
    formatQuestionType (val) {
      const obj = questionType.find(item => item.value === parseInt(val))
      if (obj) return obj.label
      return '未知'
    },
    formatDifficulty (value) {
      const obj = difficulty.find(item => parseInt(value) === item.value)
      if (obj) return obj.label
      return '未知'
    }
  },
  props: {
    showDialog: {
      type: Boolean,
      default: false
    },
    questionId: {
      type: Number,
      required: true
    }
  },
  data () {
    return {
      questionData: {}, // 问题信息
      radio: '', // 单选
      checkBox: [], // 多选
      showVideo: false // 视频显示与隐藏
    }
  },
  methods: {
    async getQuestionDetail (id) {
      const { data: res } = await detail({ id })
      this.questionData = res
      if (res.questionType === '3') return
      this.radio = res.options.find(item => item.isRight === 1).title
      this.checkBox = res.options.filter(item => item.isRight === 1).map(item => item.title)
    },
    playVideo () {
      if (!this.questionData.videoURL) {
        return this.$message.warning('该题目无视频解析')
      }
      this.showVideo = true
    },
    onClose () {
      this.questionData = {}
      this.checkBox = []
      this.radio = ''
      this.showVideo = false
      this.$emit('update:showDialog', false)
    }
  }
}
</script>

<style>
</style>
